package com.shsubway.utils;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;


import com.shsubway.R;

import java.io.File;

/**
 * Created by Hu on 2016/11/17.
 */

public class LocalImageDo {
    private PopupWindow popuWindow;//显示获取图片方式的popuwindows
    private View contentView;//底部的弹窗布局
    private View parent;
    private Button btn_camera;//相机
    private Button btn_photo;//相册
    Context context;
    Intent intent;
    String takePhotoPath;
    private File cameraFile; // 保存拍照后的图片文件
    private static final int REQUE_CODE_CAMERA = 1;
    private static final int REQUE_CODE_PHOTO = 2;
    private static final int REQUE_CODE_CROP = 3;
    OnClickButtonListener onClickButtonListener;

    public void setOnClickButtonListener(OnClickButtonListener onClickButtonListener) {
        this.onClickButtonListener = onClickButtonListener;
    }

    public LocalImageDo(View parent, Context context) {
        this.parent = parent;
        this.context = context;
        contentView = View.inflate(context, R.layout.layout_takephoto, null);
        btn_camera = (Button) contentView.findViewById(R.id.camara);
        btn_photo = (Button) contentView.findViewById(R.id.photo);

    }

    private void initEvent() {
        btn_camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClickButtonListener.OnClick(view,popuWindow);
            }
        });
        btn_photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClickButtonListener.OnClick(view,popuWindow);
            }
        });
    }

    /**
     * 显示PopupWindow用于选择图片上传方式
     */
    public void showPopuWindow() {
        if (null == popuWindow) {
            popuWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            popuWindow.setFocusable(true);
            popuWindow.setBackgroundDrawable(new BitmapDrawable());
            popuWindow.setAnimationStyle(R.style.popu_animation);
        }
        popuWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        initEvent();
    }

    public interface OnClickButtonListener{
        void OnClick(View view, PopupWindow popupWindow);
    }
}
